package com.kunbo.cn.app.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.app.service.SelectService;
import com.kunbo.cn.app.util.OrganizationDTO;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.ResultBean;

@RestController
@RequestMapping("/select")
public class SelectController {
	
	@Autowired
	private SelectService service;
	
	/**
	 * 获取通知单类型
	 * @return
	 */
	@PostMapping("/noticeType")
	public ResultBean<List<Map<String,Object>>> noticeType(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.noticeType());
	}
	
	
	/**
	 * 获取采购运单号
	 * @return
	 */
	@PostMapping("/waybillNo")
	public ResultBean<List<Map<String,Object>>> waybillNo(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.waybillNo());
	}
	
	
	/**
	 * 销售运单号
	 * @return
	 */
	@PostMapping("/saleWayBillNo")
	public ResultBean<List<Map<String,Object>>> saleWayBillNo(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.saleWayBillNo());
	}
	
	
	
	/**
	 * 获取收货单位
	 * @return
	 */
	@PostMapping("/receivingUnit")
	public ResultBean<List<Map<String,Object>>> receivingUnit(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.receivingUnit());
	}
	
	
	
	
	
	/**
	 * 获取运输单位
	 * @return
	 */
	@PostMapping("/transportUnit")
	public ResultBean<List<Map<String,Object>>>transportUnit(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.transportUnit());
	}
	
	
	/**
	 * 获取车牌号
	 * @return
	 */
	@PostMapping("/carNumber")
	public ResultBean<List<Map<String,Object>>> carNumber(
			@RequestParam("id")String id
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.carNumber(id));
	}
	
	/**
	 * 
	 * <p>Title: getAllCar</p>
	 * <p>Description:获取所有可用车辆，并能根据车牌号模糊查询 </p>
	 * @param carNumber
	 * @return
	 */
	@PostMapping("/getAllCars")
	public CommonResult getAllCar(
			@RequestParam(value="carNumber",required=false)String carNumber
			){
		
		return new CommonResult(true,"获取成功",service.getAllCar(carNumber));
	}
	
	
	
	
	/**
	 * 获取司机
	 * @return
	 */
	@PostMapping("/carDriver")
	public ResultBean<List<Map<String,Object>>> carDriver(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.carDriver());
	}
	
	
	/**
	 * 获取订单号
	 * @param wayBillCode
	 * @return
	 */
	@PostMapping("/orderCode")
	public ResultBean<String>  orderCode(
			@RequestParam("wayBillCode")String wayBillCode
			){
		ResultBean<String> result = new ResultBean<String>();
		return BuildBean.buildResult(result, "succes", "error",service.orderCode(wayBillCode));
	}
	
	
	/**
	 * 获取车辆类型
	 * @return
	 */
	@PostMapping("/carType")
	public ResultBean<List<Map<String,Object>>> carType(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.carType());
	}
	
	
	
	/**
	 * 获取装卸类型
	 *
	 * @return
	 */
	@PostMapping("/handlingType")
	public ResultBean<List<Map<String,Object>>> handlingType(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.handlingType());
	}

	
	
	/**
	 * 获取客户
	 * 
	 */
	@PostMapping("/getUsers")
	public ResultBean<List<Map<String,Object>>> getUsers(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.getUsers());
	}
	/**
	 * 获取商户
	 * @return
	 */
	@PostMapping("/getSuppliers")
	public ResultBean<List<Map<String,Object>>> getSuppliers(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.getSuppliers());
	}
	
	
	/**
	 * 获取用户类型
	 * @return
	 */
	@PostMapping("/getUserTypes")
	public ResultBean<List<Map<String,Object>>> getUserTypes(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.getUserTypes());
	}
	
	
	
	/**
	 * 获取编号
	 */
	@PostMapping("/getCode")
	public String getCode(
			@RequestParam("name")String name,
			@RequestParam("equipmentNo")String equipmentNo
			) {
	        String newEquipmentNo = "000000001";
	        if(equipmentNo != null && !equipmentNo.isEmpty()){
	            int newEquipment = Integer.parseInt(equipmentNo) + 1;
	            newEquipmentNo = String.format(name + "%09d", newEquipment);
	        }
	        return newEquipmentNo;
	}
	
	/**
	 * 获取承运商
	 * @return
	 */
	@PostMapping("/Carrier")
	public ResultBean<List<Map<String,Object>>> Carrier(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.Carrier());
	}
	/**
	 * 获取承运商用户类型
	 * @return
	 */
	@PostMapping("/CarrierUser")
	public ResultBean<List<Map<String,Object>>> CarrierUtype(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.CarrierUtype());
	}
	/**
	 * 获取物料
	 * @return
	 */
	@PostMapping("/matter")
	public ResultBean<List<Map<String,Object>>> CarrierUty(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.matter());
	}
	
	
	/**
	 * 获取供应商用户类型
	 */
	@PostMapping("/getSupplierType")
	public ResultBean<List<Map<String,Object>>> getSupplierType(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.getSupplierType());
	}
	/**
	 * 获取物料id，name
	 * @return
	 */
	@PostMapping("/matterid")
	public ResultBean<List<Map<String,Object>>>matter(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.matterid());
	}
	/**
	 * 获取井口下拉
	 * @return
	 */
	@PostMapping("/wellhead")
	public ResultBean<List<Map<String,Object>>>wellhead(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.wellhead());
	}
	
	
	/**
	 * 获取组织
	 */
	@PostMapping("/getOrganization")
	public ResultBean<List<OrganizationDTO>> getOrganization(){
		ResultBean<List<OrganizationDTO>> result = new ResultBean<List<OrganizationDTO>>();
		return BuildBean.buildResult(result, "succes", "error",service.getOrganization());
	}
	/**
	 * 获取供应商
	 * @return
	 */
	@PostMapping("/getSupplier")
	public ResultBean<List<Map<String,Object>>>getSupplier(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.getSupplier());
	}
	/**
	 * 获取物料类型
	 * @return
	 */
	@PostMapping("/getMatterType")
	public ResultBean<List<Map<String,Object>>>getMatterType(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.getMatterType());
	}

	/**
	 * 所有车牌号
	 * @return
	 */
	@PostMapping("/plateNumber")
	public ResultBean<List<Map<String,Object>>> plateNumber(
		
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.plateNumber());
	}
	/**
	 * 获取所有司机
	 * @return
	 */
	@PostMapping("/carDrivers")
	public ResultBean<List<Map<String,Object>>> carDrivers(
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.carDrivers());
	}
	
	
	

	/**
	 * 获取组织管理
	 */
	@PostMapping("/getOrganizations")
	public ResultBean<List<Map<String,Object>>> getOrganizations(){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.getOrganizations());
	}
	/**
	 * 获取物料级联物料类型
	 * @return
	 */
	@PostMapping("/getMatter")
	public ResultBean<List<Map<String,Object>>>getMatter(
			@RequestParam("mater_type")String mater_type
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",service.getMatter(mater_type));
	}
}
